<%--
@author Nuwan Koggalahewa
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">

    $(document).ready(function () {
        $('.land-table').dataTable({
            "sPaginationType": "full_numbers",
            "bDestroy": true,
            "oLanguage": {
                "sZeroRecords": $('#no-record').val(),
                "sLengthMenu": $('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch": $('#search').val(),
                "sInfo": $('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty": $('#no-record').val(),
                "oPaginate": {
                    "sFirst": $('#first').val(),
                    "sLast": $('#last').val(),
                    "sNext": $('#next').val(),
                    "sPrevious": $('#previous').val()
                }
            },
            "fnDrawCallback": function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            },
            "aLengthMenu": [
                [ 10, 25, 50],
                [10, 25, 50]
            ],
            "iDisplayLength": 50
        });

        //Onclick View link
        /*    $('#viewLink').click(function () {

         });  */
        var type = '<s:property value="searchType"/>'
        //alert("searchType"+$("[name='pageNo']").val());

        if ($("[name='pageNo']").val() != 0) {
            $('.navClass0').hide();
            $('.navClass1').hide();
            $('.navClass2').hide();
            $('.navClass3').hide();
            $('.navClass4').hide();

            if (type == 5) {
                $('.navClass0').show();
            }
            else if (type == 1) {
                $('.navClass1').show();
            } else if (type == 2) {
                $('.navClass2').show();
            } else if (type == 3) {
                $('.navClass3').show();
            } else if (type == 4) {
                $('.navClass4').show();
            }
        }

    });

    $(function () {


        $('select#district').bind('change', function (evt1) {
            var id = $("select#district").attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 2},
                    function (data) {
                        var options1 = '<option value="0"> - Select  - </option> ';
                        var ds = data.dsDivisionList;
                        for (var i = 0; i < ds.length; i++) {
                            options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'

                        }
                        $("select#dsDivision").html(options1);
                    });

        });


        $("#clearBtnId").val($("input#clearText").val()) ;

    });


    /*function loadLands() {

     var id = $("select#dsDivision").attr("value");
     var mode = "search";
     var type = "searchApprovedLandsbyDS";

     $.getJSON('${pageContext.request.contextPath}/common/LandLookupService', {id:id, mode:mode, type:type}, function(data) {
     loadLandList(data.landList);
     });
     }*/


    function viewLandDetails(landId) {
        //alert(landId);
        //ajax find land list by parent id
        var url = '${"findClildrenByParentLand.do?landId=' + landId + '"}';
        $.get(url, $(this).serialize(), function (data) {
            $("#landDetails").html(data);
            //if list contain only one element display land details
            //else
            //display in tree
        });
    }

    function clearFields(){
        $("input#searchTextLandName").val('');
        $("input#searchTextPlanNo").val('');
        $("input#searchTextLotNo").val('');
        $("input#searchTextHolderName").val('');
        $("select#district").val('0');
        $("select#dsDivision").val('0');
    }


</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="searchModule.do"><img src="${pageContext.request.contextPath}/images/search.png"
                                     alt="Land Alienation"><span><s:label
            value="%{getText('search.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="searchAllLands.do"><img
            src="${pageContext.request.contextPath}/images/searchLand.png"><span><s:label
            value="%{getText('search_all_lands.label')}"/></span></s:a>
    <div id="back-button" align="right">
                    <s:form><s:submit value="%{getText('back_btn.label')}" action="searchModule"/></s:form>
        </div>
</div>

<div class="page-title">
    <h2><s:label value="%{getText('search_all_lands.label')}"/></h2>
</div>
<div id="search-lands-form-outer">
    <s:form name="searchLandByDSUpperLevel" id="searchLandByLandName" method="POST">
    <table>
        <tr>
                <td class="left-align"><s:label value="%{getText('district.label')}"/></td>
                <td><s:select list="districtList" name="districtId" headerKey="0" headerValue="-- Select --"
                              id="district"/></td>
                <td class="left-align"><s:label value="%{getText('ds_division.label')}"/></td>
                <td><s:select name="dsDivisionId" id="dsDivision" headerKey="0" headerValue="-- Select --"
                              list="dsDivisionList" cssClass="width-180-px"/>
                </td>
                <s:hidden name="pageNo"/>
                <s:hidden name="searchType" value="5"/>
        </tr>
    </table>

    <table>
        <tr>
                <td><s:label value="%{getText('name_of_land.label')}"/></td>
                <td><s:textfield name="searchText1" id="searchTextLandName"/></td>
        </tr>
        <tr>
                <td><s:label value="%{getText('plan_no.label')}"/></td>
                <td><s:textfield name="searchText2" id="searchTextPlanNo"/></td>
        </tr>
        <tr>
                <td><s:label value="%{getText('lot_no.label')}"/></td>
                <td><s:textfield name="searchText3" id="searchTextLotNo"/></td>
        </tr>
        <tr>
                <td><s:label value="%{getText('holder_name.label')}"/></td>
                <td><s:textfield name="searchText4" id="searchTextHolderName"/></td>
        </tr>
        <tr>
            <table>
                <tr>
                    <td >
                    <s:submit action="searchAllLandByDSUpperLevel" value="%{getText('search.label')}"/>
                    </td>
                    <td>
                        <s:if test="pageNo > 1">
                            <s:submit action="searchAllLandByDSUpperLevelBackPageId" value="%{getText('previous.label')}"/>
                        </s:if>
                    </td>
                    <td>
                        <s:if test="showNextButton == true">
                        <s:submit action="searchAllLandByDSUpperLevelNextPageId" value="%{getText('next.label')}"/>
                        </s:if>
                    </td>
                    <td>

                        <input type="button" id="clearBtnId" onclick="clearFields()"/>
                    </td>
                </tr>

            </table>
        </tr>


    </table>
    </s:form>
</div>

<%--<div id="land-list">
    <table class="width-100 margin-10-auto table land-table">

    </table>
</div>--%>

<div id="landDetails">

</div>

<table id="land-table" class="width-100 margin-10-auto table land-table">
    <thead>
    <tr>
        <th><s:label value="%{getText('slmsSerialNumber.label')}"/></th>
        <th><s:label value="%{getText('name_of_the_land.label')}"/></th>
        <th><s:label value="%{getText('gn_division.label')}"/></th>
        <th><s:label value="%{getText('plan_no.label')}"/></th>
        <th><s:label value="%{getText('lot_no.label')}"/></th>
        <th><s:label value="%{getText('alienation_status.label')}"/></th>
        <th><s:label value="%{getText('approval_state.label')}"/></th>
        <th><s:label value="%{getText('action.label')}"/></th>
    </tr>
    </thead>
    <tbody>
    <s:iterator status="lands" value="landList">

        <tr>
            <td width="180px"><s:property value="id"/></td>
            <td width="80px"><s:property value="nameOfTheLand"/></td>
            <td width="80px"><s:property value="gnDivision.enDivisionName"/></td>
            <td width="80px"><s:property value="planNumber"/></td>
            <td width="80px"><s:property value="lotNumber"/></td>
            <td width="80px"><s:property value="alienationState"/></td>
            <td width="80px"><s:property value="approvalState"/></td>
            <td width="80px" class="center-align">
                <a href="#" title="View" id="viewLink" onclick="viewLandDetails('<s:property value="id"/>')">
                    <img src="${pageContext.request.contextPath}/images/detailed-form.png"
                         style="border:none; width:25px; height:25px;"/> </a>

            </td>
        </tr>

    </s:iterator>
    </tbody>
</table>




<%-- Localization text for java script generated text --%>
<s:hidden id="ref" value="%{getText('reference_no.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>
<s:hidden id="plan" value="%{getText('plan_no.label')}"/>
<s:hidden id="lot" value="%{getText('lot_no.label')}"/>
<s:hidden id="action" value="%{getText('action.label')}"/>
<s:hidden id="viewTooltip" value="%{getText('view_tooltip.label')}"/>
<s:hidden id="undifined" value="%{getText('undefined.label')}"/>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>
<s:hidden id="clearText" value="%{getText('clear.label')}" />
<s:hidden id="showNext" name="showNextButton"/>





